#include <gflags/gflags.h>

#include "mysql.hpp"
#include "mysql_user.hpp"


DEFINE_bool(run_mode, true, "是否为调试模式");
DEFINE_string(log_file, "", "发布模式下，用于指定日志的输出文件");
DEFINE_int32(log_level, 0, "发布模式下，用于指定日志输出等级");

void insert(im::UserTable &user) {
    im::User user1("uid1", "昵称1", "123456");
    user.insert(user1);
    
    im::User user2("uid2", "15566667777");
    user.insert(user2);
}

void update_by_id(im::UserTable &user_tb) {
    auto user = user_tb.select_by_id("uid1");
    user->description("我是一个风一样的男子！！");
    user_tb.update(*user);
}

void update_by_phone(im::UserTable &user_tb) {
    auto user = user_tb.select_by_phone("15566667777");
    user->password("22223333");
    user_tb.update(*user);
}

void update_by_nickname(im::UserTable &user_tb) {
    auto user = user_tb.select_by_nickname("uid2");
    user->user_name("昵称2");
    user_tb.update(*user);
}

void select_users(im::UserTable &user_tb) {
    std::vector<std::string> id_list = {"uid1", "uid2"};
    auto res = user_tb.select_multi_users(id_list);
    for (auto user : res) {
        std::cout << user.user_name() << std::endl;
    }
}
int main(int argc, char *argv[])
{
    google::ParseCommandLineFlags(&argc, &argv, true);
    im::initLogger(FLAGS_run_mode, FLAGS_log_file, FLAGS_log_level);

    auto db = im::ODBFactory::create("root", "123456", "127.0.0.1", "im", "utf8", 0, 1);

    im::UserTable user(db);

    insert(user);
    // update_by_id(user);
    // update_by_phone(user);
    update_by_nickname(user);
    select_users(user);
    return 0;
}